package com.cloud.system.interfaces;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cloud.system.api.entity.SysInfo;
import com.cloud.system.common.config.FeignConfiguration;

import feign.hystrix.FallbackFactory;

@FeignClient(value = "CUSTOM", configuration = FeignConfiguration.class, fallbackFactory = FeignCustomCustomBizFallbackFactory.class)
public interface FeignClientCustomBiz {
	@RequestMapping(value = "custom/api/interface/loadsystem", method = RequestMethod.GET)
	List<SysInfo> loadSystem(@RequestParam("parts") String parts);
}

@Component
class FeignCustomCustomBizFallbackFactory implements FallbackFactory<FeignClientCustomBiz> {
	private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientForceFallbackFactory.class);

	@Override
	public FeignClientCustomBiz create(Throwable cause) {
		return new FeignClientCustomBiz() {
			@Override
			public List<SysInfo> loadSystem(String parts) {
				if (FeignCustomCustomBizFallbackFactory.LOGGER.isDebugEnabled()) {
					FeignCustomCustomBizFallbackFactory.LOGGER
							.debug("loadSystem fallback; reason was:" + cause);
				}
				return new ArrayList<SysInfo>(0);
			}

		};
	}
}